<?php
include("../includes/DBFunctions.php");
include("../includes/getCredentials.php");

function allAnimalReportFunctor() {
	$gc = new GetCredentials;
	$uid = $gc->getUserID();
	$db = new DBFunctions;
	$db->connectDB();
	$query = "call animalReport(".$uid.",@a);";
	$result = $db->query($query);
	if( !$result ) {
		die("alert('Failed stored procedure call (animalReport)');");
	}
	$toPrint = "";
	if (mysqli_num_rows($result) < 1) {
		$db->closeDB();
		$toPrint = "<div><h3>n/a</h3></div>";;
	} else {
		while( $line = mysqli_fetch_array( $result, MYSQL_ASSOC ) ) {
			$cName = $line['CommonName'];
			$onclick = "setTitle(\\\"<h2>Animal Report</h2>\\\");var s=new Array(\\\"sid=".$line['Species_ID']."\\\");call(\\\"functors/animalReportFunctor.php\\\",s,1,0);";
			$toPrint .= "<div><h3><a href='#' onclick='".$onclick."'>".$cName."</a> <i>(".$line['ScientificName'].")</i></h3><ul><li>Heat Tolerance: ".$line['MinHeat']." - ".$line['MaxHeat']."&deg; F</li>";
			$toPrint .= "<li>Weight: ".$line['HungerIndex']." lbs</li>";
			$toPrint .= "<li>Travel Speed: ".$line['TravelSpeed']." mph</li>";
			$toPrint .= "<li>Total Population: ".number_format($line['Total_Pop'])."</li>";
			$toPrint .= "</ul></div>";
		}
		$db->closeDB();
	}
	
	echo 'displayReport("'.$toPrint.'");';
}

allAnimalReportFunctor();
?>